<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mail\VerifyEmail;
use Illuminate\Support\Facades\Mail;

class MailController extends Controller
{
    public function sendVerifyEmail(Request $request)
    {
        $email = $request->input('email');
        // 生成随机验证码
        $code = rand(100000, 999999);

        // 发送邮件
        Mail::to($email)->send(new VerifyEmail($code));

        // 将验证码存储到数据库或缓存中，用于后续验证
        // 例如存储到缓存中，有效期 5 分钟
        \Cache::put('verify_code_' . $email, $code, 300);

        return ['status' => '1', 'message' => '邮件发送成功'];
    }
}
